home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / QuitDialog.java < prev    next >
Text File  |  1998-11-02  |  4KB  |  160 lines

  1. /*
  2.     A basic extension of the java.awt.Dialog class
  3.  */
  4.  
  5. import java.awt.*;
  6. import java.awt.event.*;
  7.  
  8. public class QuitDialog extends Dialog
  9. {
  10.  
  11.     public QuitDialog(Frame parent, boolean modal)
  12.     {
  13.         super(parent, modal);
  14.  
  15.         // This code is automatically generated by Visual Cafe when you add
  16.         // components to the visual environment. It instantiates and initializes
  17.         // the components. To modify the code, only use code syntax that matches
  18.         // what Visual Cafe can generate, or Visual Cafe may be unable to back
  19.         // parse your Java file into its visual environment.
  20.         //{{INIT_CONTROLS
  21.         setLayout(null);
  22.         setSize(337,135);
  23.         setVisible(false);
  24.         yesButton.setLabel(" Yes ");
  25.         add(yesButton);
  26.         yesButton.setFont(new Font("Dialog", Font.BOLD, 12));
  27.         yesButton.setBounds(72,80,79,22);
  28.         noButton.setLabel("  No  ");
  29.         add(noButton);
  30.         noButton.setFont(new Font("Dialog", Font.BOLD, 12));
  31.         noButton.setBounds(185,80,79,22);
  32.         label1.setText("Do you really want to quit?");
  33.         label1.setAlignment(java.awt.Label.CENTER);
  34.         add(label1);
  35.         label1.setBounds(78,33,180,23);
  36.         setTitle("A Basic Application - Quit");
  37.         //}}
  38.  
  39.         //{{REGISTER_LISTENERS
  40.         SymWindow aSymWindow = new SymWindow();
  41.         this.addWindowListener(aSymWindow);
  42.         SymAction lSymAction = new SymAction();
  43.         yesButton.addActionListener(lSymAction);
  44.         noButton.addActionListener(lSymAction);
  45.         //}}
  46.     }
  47.  
  48.     public void addNotify()
  49.     {
  50.         // Record the size of the window prior to calling parents addNotify.
  51.         Dimension d = getSize();
  52.         
  53.         super.addNotify();
  54.  
  55.         if (fComponentsAdjusted)
  56.             return;
  57.  
  58.         // Adjust components according to the insets
  59.         Insets insets = getInsets();
  60.         setSize(insets.left + insets.right + d.width, insets.top + insets.bottom + d.height);
  61.         Component components[] = getComponents();
  62.         for (int i = 0; i < components.length; i++)
  63.         {
  64.             Point p = components[i].getLocation();
  65.             p.translate(insets.left, insets.top);
  66.             components[i].setLocation(p);
  67.         }
  68.         fComponentsAdjusted = true;
  69.     }
  70.  
  71.  
  72.     public QuitDialog(Frame parent, String title, boolean modal)
  73.     {
  74.         this(parent, modal);
  75.         setTitle(title);
  76.     }
  77.  
  78.  
  79.     // Used for addNotify check.
  80.     boolean fComponentsAdjusted = false;
  81.  
  82.     //{{DECLARE_CONTROLS
  83.     java.awt.Button yesButton = new java.awt.Button();
  84.     java.awt.Button noButton = new java.awt.Button();
  85.     java.awt.Label label1 = new java.awt.Label();
  86.     //}}
  87.  
  88.     private void quit()
  89.     {
  90.         Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new WindowEvent((java.awt.Window)getParent(), WindowEvent.WINDOW_CLOSING));        
  91.     }
  92.     
  93.     class SymWindow extends java.awt.event.WindowAdapter
  94.     {
  95.         public void windowClosing(java.awt.event.WindowEvent event)
  96.         {
  97.             Object object = event.getSource();
  98.             if (object == QuitDialog.this)
  99.                 QuitDialog_WindowClosing(event);
  100.         }
  101.     }
  102.  
  103.     void QuitDialog_WindowClosing(java.awt.event.WindowEvent event)
  104.     {
  105.         // to do: code goes here.
  106.              
  107.         QuitDialog_WindowClosing_Interaction1(event);
  108.     }
  109.  
  110.     void QuitDialog_WindowClosing_Interaction1(java.awt.event.WindowEvent event)
  111.     {
  112.         try {
  113.             this.dispose();
  114.         } catch (Exception e) {
  115.         }
  116.     }
  117.  
  118.     class SymAction implements java.awt.event.ActionListener
  119.     {
  120.         public void actionPerformed(java.awt.event.ActionEvent event)
  121.         {
  122.             Object object = event.getSource();
  123.             if (object == yesButton)
  124.                 yesButton_ActionPerformed(event);
  125.             else if (object == noButton)
  126.                 noButton_ActionPerformed(event);
  127.         }
  128.     }
  129.  
  130.     void yesButton_ActionPerformed(java.awt.event.ActionEvent event)
  131.     {
  132.         // to do: code goes here.
  133.              
  134.         yesButton_ActionPerformed_Interaction1(event);
  135.     }
  136.  
  137.     void yesButton_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
  138.     {
  139.         try {
  140.             this.quit();
  141.         } catch (Exception e) {
  142.         }
  143.     }
  144.  
  145.     void noButton_ActionPerformed(java.awt.event.ActionEvent event)
  146.     {
  147.         // to do: code goes here.
  148.              
  149.         noButton_ActionPerformed_Interaction1(event);
  150.     }
  151.  
  152.     void noButton_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
  153.     {
  154.         try {
  155.             this.dispose();
  156.         } catch (Exception e) {
  157.         }
  158.     }
  159. }
  160.